import deviceApi from "../../../api/deviceInfo";
import storage from '../../../utils/storage';
import {toast} from "../../../utils/util";
Page({
  data: {
    statusBarHeight: getApp().globalData.statusBarHeight,
    list: [],
    pageSize: 10,
    pageNum: 1,
    cur: 0,
    status: "more",
    userId: storage.get('userInfo').id
  },
  onLoad: function (options) {
    this.init();
  },
  changeTab (e) {
    let { index } = e.currentTarget.dataset;
    this.setData({
      cur: index
    })
  },
  init () {
    let params = {
      pageSize: this.data.pageSize,
      pageNum: this.data.pageNum,
      userId: this.data.userId
    }
    deviceApi.getWarningList(params).then(res => {
      this.data.list = this.data.list.concat(res.rows)
      this.data.pageNum++
      this.setData({
        list: this.data.list,
        pageNum: this.data.pageNum
      })
      if(res.rows.length < this.data.pageSize){
        this.setData({
          status: 'noMore',
        })
      }
    })
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if(this.data.status = 'noMore') {
      return
    }
    this.init();
  },
});